//
//  test.c
//  Tic_Tac_Toe
//
//  Created by Daniel on 2024/5/20.
//

#include "game.h"

void menu(void) {
    printf("***************************************\n");
    printf("***********  1.play  0.exit  **********\n");
    printf("***************************************\n");
}

void game(void) {
    char result = 0;
    char board[ROW][COLUMN] = {0};
    Init_board(board,ROW,COLUMN);
    Display_board(board,ROW,COLUMN);
    while (1) {
        Player_move(board,ROW,COLUMN);
        result = Judgement(board,ROW,COLUMN);//判断输赢
        Display_board(board,ROW,COLUMN);
        if(result != 'D')
            break;
        Machine_move(board,ROW,COLUMN);
        Display_board(board,ROW,COLUMN);
        result = Judgement(board,ROW,COLUMN);
        Judgement(board,ROW,COLUMN);//判断输赢
        if(result != 'D')
            break;
    }
    if( result == '*')
    {
        printf("恭喜！您赢了\n");
    }else if(result =='#')
    {
        printf("抱歉，您输了\n");
    }else
    {
        printf("平局\n");
    }
}

int main(void) {
    srand((unsigned int) time(NULL));//设置随机数的生成起点
    int input = 0;
    do {
        menu(); //show the manu
        printf("请选择：");
        scanf("%d", &input);
        switch (input) {
            case 1:
                game();
                break;
            case 0:
                printf("退出游戏\n");
                break;
            default:
                printf("选择错误\n");
                break;
        }
    } while (input);
    return 0;
}
